var saGetID = function(db, table, column, value, sql_values, callback) {

	// Call this with a table, column, and value, and if the entry already
	// exists, it will return the value of the ID field for the row. If not,
	// it will insert the values given in the sql_values field.

	// First, try to select. It doesn't look like you can use the SQLite ?
	// subsitutions in this case, so I'll make these statements by hand.

	db.get('SELECT id FROM ' + table + ' WHERE ' + column + ' = ?',  value, 
	function(err, row) {

		if (err) {
			throw("Unable to query '" + table + "' table");
		}
		else if (row === undefined) {

			// Nothing matched, so do the INSERT

			db.run('INSERT INTO ' + table + ' VALUES(' + sql_values + ')',
			function(err, res) {

				if (err) {
					throw("Error INSERTing '" + sql_values + "' into '" +
					table + "' table.\n" + err);
				}
				else {
					callback(this.lastID);
				}

			});
		}
		else {
			callback(row.id);
		}

	});

}
